<?php

namespace Users\Lib\Alidayu;


include('TopSdk.php');
//就是下面两句把我搞惨了，别嫌弃，我只是入门了而已
use TopClient; 
use AlibabaAliqinFcSmsNumSendRequest;

class SendSMS {
    
	protected $tpls = array();
	
	/**
     * 架构函数
     * @access public
     * @param array $tpls  初始化数组元素模板数组，根据阿里大鱼的数据
     */
    public function __construct($tpls = array()) {
        $this->tpls = $tpls;
    }
	
	
    public function send($mobile='', $tplkey='',$params,$signName='阳光灿烂'){
    	if($mobile)
    	//短信模板
    	$tpls = $this->tpls;
    	$tpl = $tpls[$tplkey];
    	if(!$tpl){
    		return -1; //'模板不存在'
    	}
        $c = new TopClient;
        $c->format = "json";
        $c->appkey = C('AlidayuAppKey');
        $c->secretKey = C('AlidayuAppSecret');
        $req = new AlibabaAliqinFcSmsNumSendRequest;
		$req->setSmsType("normal");
		$req->setSmsFreeSignName($signName);
		//$req->setSmsParam("{\"code\":\"{$code}\",\"product\":\"{$product}\"}");
		$req->setSmsParam($params);
		$req->setRecNum($mobile);
		$req->setSmsTemplateCode($tpl['key']);
		$resp = $c->execute($req);
        return object_array($resp); //变成数组
    }
    
    
    
}